Fix pin ergonomics borrowck for transient pinned borrows#1
Merged
frank-king merged 1 commit intofrank-king:feature/pin-borrowckfrom Apr 28, 2026
Merged
Conversation
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix a false pinned-borrow diagnostic in
pin_ergonomicsborrow checking for validT: Unpincoercions involvingPin<&mut T>::as_mut().The fix distinguishes user-written
&pinborrows, which create persistent pinned-place facts, from compiler-generated pinned adjustments and coercions, which should not create long-lived pin facts.What changed
mir::PinBorrowKindto distinguishPersistentandTransientpinned borrows.&pin mut placeand&pin const placelowering asPinBorrowKind::Persistent.AutoBorrow::Pinlowering asPinBorrowKind::Transient.Pinsdataflow so it records long-lived pin facts only for persistent pinned borrows.T: Unpincoercion round trips,Pin<&mut T>::get_mut()followed byas_mut()regression path,&pin mut pair.0.Why
tests/ui/pin-ergonomics/pin-coercion.rsrejected validT: Unpincoercion code aroundPin<&mut T>::as_mut()with:The previous dataflow treated every
BorrowKind::Pinnedborrow as a long-lived pin fact. That included compiler-generated pinned adjustments used for method receivers and coercions. Those transient adjustments should not make later validT: Unpincoercion code look like it is mutably borrowing an already pinned place.This is not a broad
Unpinfilter: explicit user&pinborrows ofUnpinvalues still create persistent pin facts and remain protected until reassignment.Tests
Passed:
Notes for reviewers
The main review point is whether every explicit user
&pinpath is represented asPinBorrowKind::Persistent, and whether any explicit user pinning path reaches MIR only throughAutoBorrow::Pin.Transient pinned borrows are still treated as normal live borrows; the change is only that they no longer create long-lived expired pin facts in the
Pinsdataflow.Related
&pin mut|const $placerust-lang/rust#153693